package com.iqunxing.redis.redisInAction.ch05;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.logging.LogLevel;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class LogService {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    public void logRecent(String name, String message, LogLevel level) {
        String destination = "recent:" + name + ':' + level.name();
        BoundListOperations<String, String> ops = redisTemplate.boundListOps(destination);
        ops.leftPush(message);
        ops.trim(0, 99);
    }

}
